package com.edu.service.handler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Auther:zzp
 * @Date:2025/11/10-20:50:34
 */
public class LogHandler implements InvocationHandler {

    private Object target;

    public LogHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        method.setAccessible(true);
        long startTime = System.currentTimeMillis();
        if(!method.getName().contains("sele")){
            System.out.println("执行"+method.getName()+"时间为:"+new Date());
            System.out.println("-----------------------------------------------------------------------------------");
        }
        Object result = method.invoke(target,args);
        if(method.getName().contains("sele")){
            long end = System.currentTimeMillis();
            System.out.println("执行查询方法耗时"+(end - startTime)+"ms");
            System.out.println("-----------------------------------------------------------------------------------");
        }
        return result;
    }
}
